package com.example.library.http;


import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by dadong on 2018/8/17.
 * Describe:
 */
public class ApiMethods {
    public static void ApiSubscribe(Observable observable, Observer observer) {
        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public static void getKnowledgeParse(Observer<KnowledgeParseEntity> observer, String knowledge, String levelCode, String schoolId, String stageNo, String stuId) {
        //   String dictString = "{" + "\"knowledge\"" + ":" + "\"" + knowledge + "\"" + "," + "\"levelCode\"" + ":" + "\"" + levelCode + "\"" + "}";
        try {
            JSONObject dictString = new JSONObject();
            dictString.put("knowledge", knowledge);
            dictString.put("levelCode", levelCode);
            dictString.put("schoolId", schoolId);
            dictString.put("stageNo", stageNo);
            dictString.put("stuId", stuId);
//            ApiSubscribe(Api.getApiService().getKnowLedgeParse(dictString.toString()), observer);
            ApiSubscribe(Api.getApiService().getKnowLedgeParseByCode(dictString.toString()), observer);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public static void getKnowledge(Observer<List<KnowledgeEntity>> observer, String text, String stageNo) {
        try {
            JSONObject dictString = new JSONObject();
            dictString.put("text", text);
            dictString.put("stageNo", stageNo);
            ApiSubscribe(Api.getApiService().getKnowledge(dictString.toString()), observer);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
